package BaiDu;

import java.util.Scanner;
import java.util.Stack;

public class Main_0913_3 {
    public static void main(String[] args) {
        //用栈，遇到会有大括号的地方入栈，遇到右括号出栈
        Scanner cin=new Scanner(System.in);
        Stack<String> stack=new Stack<>();
        int level=0;
        int res=0;
        while (cin.hasNext()){
            String line=cin.nextLine();
            if (line.contains("for")){
                stack.push(line);
                level++;
                res=Math.max(res,level);
            }
            if (line.contains("if")){
                stack.push(line);
            }
            if (line.contains("}")&&!stack.isEmpty()){
                String top = stack.pop();
                if (top.contains("for")){
                    level--;
                }
            }
        }
        System.out.println(res);
    }
}
